package com.xuzhen.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xuzhen.domain.Account;
import com.xuzhen.domain.MonthReport;
import com.xuzhen.domain.User;
import com.xuzhen.service.MonthReportService;

@Transactional
@Service("monthReportServiceDelete")
public class MonthReportServiceDelete {
	@Autowired
	private MonthReportService monthReportService;

	/**
	 * 当新增一条消费收入记录时，对应的报表也做相应的处理
	 * 
	 * @param inOutOrder
	 *            消费or收入记录
	 */
	public void tigerAddWhenAddInOutOrder(Account account) {
		User user = new User();
		user.setId(1L);
		MonthReport monthReport = monthReportService.findByUserAndTypeAndDate(
				user, account.getNoteDate(), account.getType());
		if (monthReport == null) {
			monthReport = new MonthReport();
			monthReport.setAmount(account.getAmount());
			monthReport.setMonth(account.getNoteDate());
			monthReport.setType(account.getType());
			monthReport.setUser(user);
			monthReportService.add(monthReport);
			return;
		}
		monthReport.setAmount(monthReport.getAmount() + account.getAmount());
		monthReportService.update(monthReport);
	}

}
